package com.datang.pet.api.labelController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-12 08:39
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.pojo.Label;
import com.datang.pet.service.LabelService;
import com.datang.pet.vo.GetLabelListResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LabelController {

    @Autowired
    private LabelService labelService;

    /*
     * @author 顶风少年
     * @date 2019/6/12 9:33
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param label
     * @result Result
     * @notify 添加标签
     * version 1.0
     */
    @PostMapping("/addLabel")
    public Result addLabel(@RequestBody Label label) throws Exception {
        //UserId是否为空
        if (!StringUtils.isNUll(label.getUserId())) {
            throw new Exception("不能没有发布人");
        }
        labelService.addLabel(label);
        return Result.ok(null);
    }

    /*
     * @author 顶风少年
     * @date 2019/6/12 9:33
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result Result
     * @notify 获取标签
     * version 1.0
     */
    @GetMapping("/getLabelList")
    public Result getLabelList() throws Exception {
        List<GetLabelListResponse> labels = labelService.getLabelList();
        return Result.ok(labels);
    }
}
